
** Chicago Area Study -- Clean/code relevant variables **

*****************************************
** Dependent variable -- participation **
*****************************************

foreach var of varlist q6_1-q6_10{
destring `var', replace
}

gen petition=0
replace petition=1 if q6_1==1

gen share=0
replace share=1 if q6_2==1

gen protest=0
replace protest=1 if q6_3==1

gen letter=0
replace letter=1 if q6_4==1
replace letter=1 if q6_5==1

gen donate =0
replace donate=1 if q6_6==1
replace donate=1 if q6_7==1

gen volunteer=0
replace volunteer=1 if q6_8==1

gen opinion=0
replace opinion=1 if q6_9==1
replace opinion=1 if q6_10==1

* non-voting participation
gen act_index=petition+share+protest+letter+donate+volunteer+opinion

* voter registration
destring q9, replace
destring q10, replace

gen reg=0
replace reg=1 if q9==4

* voted?
gen vote=0
replace vote=1 if q10==1

***************************
** Independent variables **
***************************

* criminal justice contact

foreach var of varlist q31_3-q31_5{
destring `var', replace
}

gen questioned=0
replace questioned=1 if q31_3==1

gen probation=0
replace probation=1 if q31_4==1

gen prison=0
replace prison=1 if q31_5==1

gen custodial=0
replace custodial=1 if probation==1
replace custodial=1 if prison==1

* connection to CSO

gen org=0
replace org=1 if q12_7==1
replace org=1 if q12_1==1
replace org=1 if q12_4==1
replace org=1 if q12_9==1
replace org=1 if q12_11==1
replace org=1 if q12_10==1
replace org=1 if q12_15==1
replace org=1 if q12_16==1


* Demographic controls

foreach var of varlist q98_1_1-q104{
destring `var', replace
}

gen foreign=0
replace foreign=1 if q98_1_1==2

gen rep=0
replace rep=1 if q104==2
gen dem=0
replace dem=1 if q104==1
gen ind=0
replace ind=1 if q104==3
replace ind=1 if q104==4

gen fem=0
replace fem=1 if ppgender==2

gen age=ppage

gen young=0
replace young=1 if age <35

gen old=0
replace old=1 if age >64

gen midlife=0
replace midlife=1 if young==0 & old==0 & age !=.

gen educ=ppeducat

foreach var of varlist q79_1-q79_3{
destring `var', replace
}

gen white=0
replace white=1 if q5_1=="1"

gen black=0
replace black=1 if q5_2=="1"

gen latino=0
replace latino=1 if q5_3=="1"

gen other=0
replace other=1 if white==0 & black==0 & latino==0

gen race=.
replace race=1 if white==1
replace race=2 if black==1
replace race=3 if latino==1
replace race=4 if other==1

gen inc = ppincimp
gen inc1=.
replace inc1=1 if inc<8
replace inc1=2 if inc>=8 & inc <12
replace inc1=3 if inc==12
replace inc1=3 if inc==13
replace inc1=4 if inc==14
replace inc1=4 if inc==15
replace inc1=5 if inc==16
replace inc1=5 if inc==17
replace inc1=6 if inc==18
replace inc1=6 if inc==19


gen married=0
replace married=1 if ppmarit==1

gen unemp=0
replace unemp=1 if ppwork==3
replace unemp=1 if ppwork==4
replace unemp=1 if ppwork==7

gen eff2=q92_2
recode eff2 1=4 4=1 2=3 3=2

gen polint=.
replace polint=1 if q91=="4"
replace polint=2 if q91=="3"
replace polint=3 if q91=="2"
replace polint=4 if q91=="1"


******************
** Make Weights **
******************

gen hweight=1
replace hweight=hweight*1.365877007 if fem==0
replace hweight=hweight*0.800204454 if fem==1

replace hweight=hweight*1.45 if young==1
replace hweight=hweight*0.9 if midlife==1
replace hweight=hweight*0.87 if old==1

replace hweight=hweight*1.25 if race==1
replace hweight=hweight*0.45 if race==2
replace hweight=hweight*1.4 if race==3
replace hweight=hweight*2.0 if race==4

replace hweight=hweight*1.383454235 if inc1==1
replace hweight=hweight*0.91 if inc1==2
replace hweight=hweight*0.819038686 if inc1==3
replace hweight=hweight*0.685485787 if inc1==4
replace hweight=hweight*.96 if inc1==5
replace hweight=hweight*1.75 if inc1==6

replace hweight=hweight*5 if educ==1
replace hweight=hweight*2.42 if educ==2
replace hweight=hweight*.8 if educ==3
replace hweight=hweight*.7 if educ==4


* trim weights 
* adjust the bottom 2.5 and top 2.5 percent so that they are closer to the distribution

**** bring up the bottom ****
replace hweight=hweight+.01 if hweight<=.16
replace hweight=hweight+.02 if hweight<=.17
replace hweight=hweight+.03 if hweight<=.18


**** bring down the top ****
replace hweight=hweight-3.5 if hweight>=14
replace hweight=hweight-3.25 if hweight>=13
replace hweight=hweight-3 if hweight>=12
replace hweight=hweight-2.75 if hweight>=11
replace hweight=hweight-2.5 if hweight>=10
replace hweight=hweight-2.25 if hweight>=9
replace hweight=hweight-2 if hweight>=8
replace hweight=hweight-1.75 if hweight>=7
replace hweight=hweight-1.5 if hweight>=6
replace hweight=hweight-1.25 if hweight>=5
replace hweight=hweight-1 if hweight>=4
replace hweight=hweight-.5 if hweight>=3

replace hweight=hweight/.90951036

tab fem [iw=hweight]
tab young [iw=hweight]
tab midlife [iw=hweight]
tab old [iw=hweight]
tab race [iw=hweight]
tab inc1 [iw=hweight]
tab educ [iw=hweight]



